home *** CD-ROM | disk | FTP | other *** search
- unit BDEDoRx2;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, BDEDoRxS, DB, DBTables, DBITypes, DBIProcs,
- DBIErrs, FileCtrl, ExtCtrls, Menus;
-
- type
- TRefIntFrm = class(TForm)
- ListBox1: TListBox;
- ListBox2: TListBox;
- ListBox3: TListBox;
- FileListBox1: TFileListBox;
- AddBtn: TButton;
- CloseBtn: TButton;
- Edit1: TEdit;
- RadioGroup1: TRadioGroup;
- CheckBox1: TCheckBox;
- Bevel1: TBevel;
- Label2: TLabel;
- Bevel2: TBevel;
- Label1: TLabel;
- ListBox4: TListBox;
- DelBtn: TButton;
- Bevel3: TBevel;
- Bevel4: TBevel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- PopupMenu1: TPopupMenu;
- RIInfo: TMenuItem;
- DepInfo: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure ListBox1DblClick(Sender: TObject);
- procedure FileListBox1DblClick(Sender: TObject);
- procedure ListBoxesDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- procedure AddBtnClick(Sender: TObject);
- procedure Edit1Change(Sender: TObject);
- procedure DelBtnClick(Sender: TObject);
- procedure ListBox4Click(Sender: TObject);
- procedure CloseBtnClick(Sender: TObject);
- procedure RIInfoClick(Sender: TObject);
- procedure PopupMenu1Popup(Sender: TObject);
- procedure DepInfoClick(Sender: TObject);
- private
- { Private-Deklarationen }
- procedure SetControlState;
- public
- { Public-Deklarationen }
- end;
-
- var
- RefIntFrm: TRefIntFrm;
-
- implementation
-
- uses BDEDoRx1, BDEDoRx6;
-
- {$R *.DFM}
-
- function GetDBPath(AliasName: string): TFileName;
- var ParamList: TStringList;
- i: integer;
- begin
- ParamList := TStringList.Create;
- with Session do
- try
- for i:=0 to pred(DatabaseCount) do
- if (Databases[i].DatabaseName = AliasName) then
- ParamList.Assign(Databases[i].Params);
- Result := UpperCase(ParamList.Values['PATH'])+'\';
- finally
- Paramlist.Free;
- end;
- end;
-
- procedure TRefIntFrm.ListBox1DblClick(Sender: TObject);
- begin
- with ListBox1 do
- if (ListBox2.Items.IndexOf(Items.Strings[ItemIndex]) = -1) then
- ListBox2.Items.Add(Items.Strings[ItemIndex])
- else
- ListBox2.Items.Delete(ListBox2.Items.IndexOf(Items.Strings[ItemIndex]));
- end;
-
- function GetFldType(const FldName: string; FldList: TDoRxList): string;
- var i: integer;
- begin
- for i:=0 to pred(FldList.Count) do
- if CompareText(TStringList(FldList.Items[i]).Strings[0],FldName) = 0 then
- Result := TStringList(FldList.Items[i]).Strings[1];
- end;
-
- function GetFldTypeFromString(const FldName: string): string;
- begin
- Result := Copy(FldName,Pos('(',FldName),3);
- end;
-
- function StripFldTypeFromString(const FldName: string): string;
- begin
- Result := FldName;
- Delete(Result,Pos('(',FldName)-1,4);
- end;
-
- function CompareFldTypes(const FldName1, FldName2: string): boolean;
- var c1,c2: string[1];
- begin
- c1 := GetFldTypeFromString(FldName1);
- c2 := GetFldTypeFromString(FldName2);
- Result := (CompareText(c1,c2) = 0)
- or ((c1[1] in ['I','+']) and (c2[1] in ['I','+']));
- end;
-
- procedure TRefIntFrm.FileListBox1DblClick(Sender: TObject);
- var TmpTbl: TTable;
- TmpFld: string;
- Pos, i: integer;
- FldList: TDoRxList;
- begin
- if FileListBox1.ItemIndex = -1 then Exit;
- ListBox3.Items.Clear;
- TmpTbl := TTable.Create(nil);
- with TmpTbl do
- try
- DataBaseName := MainFrm.Database1.DatabaseName;
- TableName := ExtractFileName(FileListBox1.FileName);
- Open;
- IndexDefs.Update;
- if IndexDefs.Count < 1 then
- ShowMessage('Table has no primary index!')
- else
- begin
- FldList := TDoRxList.Create;
- try
- BDEGetFieldStructure(TmpTbl, FldList);
- Pos := 1;
- while (Pos <= Length(IndexDefs.Items[0].Fields)) do
- begin
- TmpFld := ExtractFieldName(IndexDefs.Items[0].Fields, Pos);
- ListBox3.Items.Add(TmpFld+' ('+GetFldType(TmpFld,FldList)+')');
- end;
- finally
- FldList.FreeAll;
- FldList.Free;
- end;
- end;
- finally
- Free;
- end;
- end;
-
- procedure TRefIntFrm.ListBoxesDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- var Tw: integer;
- begin
- with (Control as TListBox).Canvas do
- begin
- Brush.Color := clWindow;
- FillRect(Rect);
- Font.Color := clBlack;
- Tw := TextWidth((Control as TListBox).Items[Index]);
- TextOut(Rect.Left+((Rect.Right-Rect.Left-Tw) div 2),
- Rect.Top, (Control as TListBox).Items[Index]);
- end;
- SetControlState;
- end;
-
- procedure TRefIntFrm.SetControlState;
- var BtnEnable: boolean;
- i: integer;
- begin
- BtnEnable := (ListBox2.Items.Count > 0)
- and (ListBox2.Items.Count = ListBox3.Items.Count)
- and (Edit1.Text > '')
- and (ListBox4.Items.IndexOf(Edit1.Text) = -1);
- if BtnEnable then
- for i:=0 to pred(ListBox2.Items.Count) do
- BtnEnable := CompareFldTypes(ListBox2.Items[i],ListBox3.Items[i]);
- AddBtn.Enabled := BtnEnable;
- DelBtn.Enabled := ListBox4.ItemIndex <> -1;
- end;
-
- procedure TRefIntFrm.Edit1Change(Sender: TObject);
- begin
- SetControlState;
- end;
-
- procedure TRefIntFrm.ListBox4Click(Sender: TObject);
- begin
- SetControlState;
- end;
-
- procedure TRefIntFrm.AddBtnClick(Sender: TObject);
- const CRintQual: array[0..1] of RINTQual = (rintRESTRICT,rintCASCADE);
- var Fields1, Fields2: string;
- i: integer;
- begin
- Fields1 := '';
- Fields2 := '';
- for i:=0 to pred(ListBox2.Items.Count) do
- Fields1 := Fields1+StripFldTypeFromString(ListBox2.Items[i])+';';
- SetLength(Fields1,Length(Fields1)-1);
- for i:=0 to pred(ListBox3.Items.Count) do
- Fields2 := Fields2+StripFldTypeFromString(ListBox3.Items[i])+';';
- SetLength(Fields2,Length(Fields2)-1);
- try
- BDEAddRIConstraint(MainFrm.Table1,
- ExtractFileName(FileListBox1.FileName),
- Edit1.Text,
- CRintQual[RadioGroup1.ItemIndex],
- rintRESTRICT,
- CheckBox1.Checked,
- Fields1, Fields2);
- except
- on E:EDoRxKeyViol do
- ShowMessage(E.Message);
- else raise;
- end;
- BDEGetRIList(MainFrm.Table1, ListBox4.Items);
- end;
-
- procedure TRefIntFrm.DelBtnClick(Sender: TObject);
- begin
- with ListBox4 do
- BDEDropRIConstraint(MainFrm.Table1, Items[ItemIndex]);
- BDEGetRIList(MainFrm.Table1, ListBox4.Items);
- end;
-
- procedure TRefIntFrm.FormCreate(Sender: TObject);
- var i: integer;
- begin
- CalcControlSize(self);
- CalcCenterPos(nil, self);
- with MainFrm.StrucGrid do
- for i:=1 to pred(RowCount) do
- ListBox1.Items.Add(Rows[i].Strings[0]+' ('+Rows[i].Strings[1]+')');
- FileListBox1.Directory := GetDBPath(MainFrm.Database1.DataBaseName);
- BDEGetRIList(MainFrm.Table1, ListBox4.Items);
- end;
-
- procedure TRefIntFrm.CloseBtnClick(Sender: TObject);
- begin
- ModalResult := mrOK;
- end;
-
- procedure TRefIntFrm.RIInfoClick(Sender: TObject);
- var RIList: TStringList;
- InfoForm: TInfoFrm;
- begin
- RIList := TStringList.Create;
- with RIList do
- try
- BDEGetRIDefsByName(MainFrm.Table1,ListBox4.Items[ListBox4.ItemIndex],RIList);
- InfoForm := TInfoFrm.Create(Application);
- with InfoForm.Memo1 do
- try
- Lines.Clear;
- Lines.Add('Properties of RI constraint '+Values['Name']+':');
- Lines.Add('');
- Lines.Add('Type: '+#9#9+Values['Type']);
- Lines.Add('DelOp: '+#9#9+Values['DelOp']);
- Lines.Add('ModeOp: '+#9#9+Values['ModOp']);
- Lines.Add('Other table: '+#9+Values['OtherTbl']);
- Lines.Add('FieldNos in this table: '+#9+Values['ThisTabFlds']);
- Lines.Add('FieldNos in other table: '+#9+Values['OthTabFlds']);
- InfoForm.ShowModal;
- finally
- InfoForm.Free;
- end;
- finally
- RIList.Free;
- end;
- end;
-
- procedure TRefIntFrm.PopupMenu1Popup(Sender: TObject);
- begin
- RIInfo.Enabled := (ListBox4.ItemIndex > -1);
- end;
-
- procedure TRefIntFrm.DepInfoClick(Sender: TObject);
- var RIList: TStringList;
- InfoForm: TInfoFrm;
- i: integer;
- begin
- RIList := TStringList.Create;
- with RIList do
- try
- InfoForm := TInfoFrm.Create(Application);
- with InfoForm.Memo1 do
- try
- Lines.Clear;
- Lines.Add('Dependent tables:');
- Lines.Add('');
- for i:=1 to MainFrm.FCurProps.iRefIntChecks do
- begin
- BDEGetRIDefsByNumber(MainFrm.Table1,i,RIList);
- if (CompareText(Values['Type'],'rintMASTER') = 0) then
- begin
- Lines.Add(Values['OtherTbl']);
- end;
- if (Lines.Count = 2) then
- Lines.Add('There are no dependent tables');
- end;
- InfoForm.ShowModal;
- finally
- InfoForm.Free;
- end;
- finally
- RIList.Free;
- end;
- end;
-
- initialization
- begin
- RefIntFrm := nil;
- end;
-
- end.
-